package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class DiveCourse implements Parcelable, Comparable<DiveCourse> {

    private static final String TAG = DiveCourse.class.getName();

    private long mId;
    private String mName;
    private DiveOrganization mOrganization;

    public DiveCourse() {}

    public DiveCourse(long id, String name, DiveOrganization organization) {
        this.setId(id);
        this.setName(name);
        this.setOrganization(organization);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }
    
    public String getName() {
        return mName;
    }

    public void setName(String name) {
        this.mName = name;
    }

    public DiveOrganization getOrganization() {
        return mOrganization;
    }

    public void setOrganization(DiveOrganization organization) {
        this.mOrganization = organization;
    }
    
    public String getFullName() {
        return String.format("%s %s", mOrganization.getName(), mName);
    }

    @Override
    public int compareTo(@NonNull DiveCourse another) {
        return this.mName.compareTo(another.mName);
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeString(mName);
        dest.writeParcelable(mOrganization, flags);
    }

    public static final Parcelable.Creator<DiveCourse> CREATOR = new Parcelable.Creator<DiveCourse>() {

        public DiveCourse createFromParcel(Parcel in) {
            return new DiveCourse(in);
        }

        public DiveCourse[] newArray(int size) {
            return new DiveCourse[size];
        }
    };

    private DiveCourse(Parcel in) {
        mId = in.readLong();
        mName = in.readString();
        mOrganization = in.readParcelable(DiveOrganization.class.getClassLoader());
    }
}
